package com.zyh.zhukang.demand.controller;

import com.zyh.zhukang.demand.VO.JsonResultVO;
import com.zyh.zhukang.demand.entity.Demand;
import com.zyh.zhukang.demand.service.DemandService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * 作者:zhuyunhao
 * 时间:2020/1/16 0016 14:19
 */
@Controller
@RequestMapping("/demand")
public class DemandController {
    @Resource
    private DemandService demandService;

    //添加商品到需求清单
    @RequestMapping("/add")
    @ResponseBody
    public JsonResultVO addDemand(@RequestBody Demand demand){
        try {
            demandService.addDemand(demand);
            return JsonResultVO.createSuccessJsonResult(null);
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResultVO.createFailJsonResult("0","添加失败");
        }

    }

    //查询用户下的需求清单
    @RequestMapping("/findDemand")
    @ResponseBody
    public List<Demand> findDemand(Integer userId){
        List<Demand> demands = demandService.findDemand(userId);
        return demands;
    }
}
